<template>
  <div class="app-container">
    <span v-model="msg"></span>
    <el-drawer
      :title="drawerTitle"
      :before-close="closeDime"
      :visible.sync="targetDimensionalityFlag"
      direction="rtl"
      ref="drawer"
      custom-class="demo-drawer"
    >
      <div style="margin-left: 30px" class="demo-drawer__content">
        <el-form :rules="dimeRules" label-position="right" ref="dimeForm" label-width="80px"
                 :model="targetDimensionality">
          <el-form-item label="维度名称" prop="dimensionalityName">
            <el-input style="width: 300px;" v-model="targetDimensionality.dimensionalityName"
                      autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="指标类型">
            <el-radio v-model="targetDimensionality.targetType" label="业绩指标">业绩指标</el-radio>
            <el-radio v-model="targetDimensionality.targetType" label="加分项">加分项</el-radio>
            <el-radio v-model="targetDimensionality.targetType" label="任务指标">任务指标</el-radio>
            <el-radio v-model="targetDimensionality.targetType" label="减分项">减分项</el-radio>
          </el-form-item>
          <el-form-item label="权重" prop="weight">
            <el-input-number style="width: 300px;" :min="1.00" :max="100.00" :controls="false"
                             v-model="targetDimensionality.weight"
                             :precision="2"></el-input-number>
          </el-form-item>
        </el-form>
        <div style="margin-top: 100px" class="demo-drawer__footer">
          <el-button style="width: 190px" type="primary" @click="dimensionalitySubmit">确 定</el-button>
          <el-button style="width: 190px" @click="closeDime">取 消</el-button>
        </div>
      </div>
    </el-drawer>
    <el-drawer
      title="选择指标项"
      :visible.sync="selectLineFlag"
      :before-close="closeTarget"
      custom-class="demo-drawer"
      size="40%"
      direction="rtl"
    >
      <hr>
      <div class="head-container" style="padding: 10px">
        <el-row :gutter="20">
          <el-col :span="4" :xs="24">
            <div class="head-container">
              <el-tree :default-expand-all="true" :data="data" :props="defaultProps"
                       @node-click="handleNodeClick"></el-tree>
            </div>
          </el-col>
          <el-col :span="20" :xs="20">
            <el-form @submit.native.prevent :model="targetParams" ref="targetParamsFrom" size="small"
                     :inline="true">
              <el-form-item>
                <el-input @keyup.enter.native="selectLine(targetIndex)" placeholder="请输入内容"
                          v-model="targetParams.targetLabel">
                  <el-button slot="append" icon="el-icon-search" @click="selectLine(targetIndex)"></el-button>
                </el-input>
              </el-form-item>
            </el-form>
            <el-table @selection-change="handleSelectionChange" :header-cell-style="{'text-align':'center'}"
                      :data="targetList">
              <el-table-column type="selection"></el-table-column>
              <el-table-column align="center" property="targetLabel" label="指标名称"></el-table-column>
              <el-table-column align="center" property="weight" label="指标权重"></el-table-column>
            </el-table>
            <pagination
              v-show="lintotal>0"
              :total="lintotal"
              :page.sync="targetParams.pageNum"
              :limit.sync="targetParams.pageSize"
              @pagination="selectLine(targetIndex)"
            />
          </el-col>
        </el-row>
        <div style="margin-top: 400px;float: right;" class="demo-drawer__footer">
          <el-button @click="closeTarget">取 消</el-button>
          <el-button type="primary" @click="selectionTarget">确 定</el-button>
        </div>
      </div>
    </el-drawer>
    <el-drawer
      title="新增指标"
      :before-close="reTargetCel"
      :visible.sync="targetFlag"
      direction="rtl"
      ref="drawer"
      custom-class="demo-drawer"
    >
      <div style="margin-left: 30px" class="demo-drawer__content">
        <el-form label-position="left" :rules="targetRules" ref="targetForm" label-width="140px"
                 :model="targetForm">
          <el-form-item label="指标名称" prop="targetLabel">
            <el-input style="width: 300px;" v-model="targetForm.targetLabel"
                      autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="指标说明">
            <el-input
              type="textarea"
              style="width: 300px;"
              :autosize="{ minRows: 2, maxRows: 4}"
              placeholder="请输入内容"
              v-model="targetForm.targetInfo"/>
          </el-form-item>
          <el-form-item label="考核标准">
            <el-input
              type="textarea"
              style="width: 300px;"
              :autosize="{ minRows: 2, maxRows: 4}"
              placeholder="请输入内容"
              v-model="targetForm.assessCriterion"/>
          </el-form-item>
          <el-form-item label="评分上限" prop="scoreCeiling">
            <el-input-number :min="1.00" :max="100.00" :controls="false" v-model="targetForm.scoreCeiling"
                             :precision="2">
              <i slot="suffix" class="el-input__icon el-icon-date"></i>
            </el-input-number>
          </el-form-item>
          <el-form-item label="权重" prop="weight">
            <el-input-number :min="1.00" :max="100.00" :controls="false" v-model="targetForm.weight" :precision="2">
              <template>%</template>
            </el-input-number>
          </el-form-item>
          <el-form-item label="备注">
            <el-input
              type="textarea"
              style="width: 300px;"
              :autosize="{ minRows: 2, maxRows: 4}"
              placeholder="请输入内容"
              v-model="targetForm.targetRemark"/>
          </el-form-item>
          <el-form-item label="是否加入指标库">
            <el-radio v-model="targetForm.status" label="1">是</el-radio>
            <el-radio v-model="targetForm.status" label="0">否</el-radio>
          </el-form-item>
          <el-form-item v-if="targetForm.status == '1'" label="选择分类" prop="parentId" label-width="100px">
            <el-select v-model="treeData" placeholder="请选择..." style="width: 16rem">
              <el-option :value="treeDataValue" style="height: auto">
                <el-tree v-model="targetForm.typeId"
                         ref="tree"
                         default-expand-all
                         accordion
                         node-key="id"
                         :data="data"
                         :props="defaultProps"
                         @node-click="handNodeClick"></el-tree>
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div style="margin-top: 100px" class="demo-drawer__footer">
          <el-button style="width: 190px" type="primary" @click="addTarget">确 定</el-button>
          <el-button style="width: 190px" @click="reTargetCel">取 消</el-button>
        </div>
      </div>
    </el-drawer>
    <el-drawer
      title="修改考核结果"
      :visible.sync="drawer"
      :before-close="befoResultClose"
      direction="ltr"
      size="60%">
      <el-table
        :data="targetResultList">
        <el-table-column align="center" prop="grade" label="等级">
          <template slot-scope="scope">
            <el-input class="TargetInput" type="text" style="width: 80px" v-model="scope.row.grade"/>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="coefficient" label="系数">
          <template slot-scope="scope">
            <el-input-number class="TargetInput" :min="0.00" :max="100.00"
                             style="width: 80px"
                             :controls="false" v-model="scope.row.coefficient" :precision="2">
            </el-input-number>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="startScore" label="分数范围">
          <template slot-scope="scope">
            <el-input-number class="TargetInput" :min="1.00" :max="1000.00"
                             style="width: 80px"
                             :controls="false" v-model="scope.row.startScore" :precision="2">
            </el-input-number>
            ≤ 分数 ≤
            <el-input-number class="TargetInput" :min="1.00" :max="1000.00"
                             style="width: 80px"
                             :controls="false" v-model="scope.row.endScore" :precision="2">
            </el-input-number>
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作">
          <template slot-scope="scope">
            <el-button @click="removeResult(scope.row)" class="el-icon-delete"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-button @click="resultDialog = true" type="primary">新增</el-button>
      <div>
        <el-drawer
          title="结果设置!"
          :append-to-body="true"
          :before-close="resultClose"
          :visible.sync="resultDialog"
          direction="ltr">
          <div style="margin-left: 60px" class="demo-drawer__content">
            <el-form ref="form" :model="resultForm" label-width="80px">
              <el-row :gutter="20">
                <el-col :span="18">
                  <el-form-item label="等级">
                    <el-input v-model="resultForm.grade"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="10">
                  <el-form-item label="系数">
                    <el-input-number :min="0.00" :max="99.00"

                                     :controls="false" v-model="resultForm.coefficient" :precision="2">
                    </el-input-number>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="9">
                  <el-form-item label="分数范围">
                    <el-input-number :min="1.00" :max="100.00"
                                     style="width: 100px"
                                     :controls="false" v-model="resultForm.startScore" :precision="2">
                    </el-input-number>
                  </el-form-item>
                </el-col>
                <el-col :span="9">
                  <el-form-item label="≤ 分数 ≤">
                    <el-input-number :min="1.00" :max="100.00"
                                     style="width: 100px"
                                     :controls="false" v-model="resultForm.endScore" :precision="2">
                    </el-input-number>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
            <div style="margin-top: 50px" class="demo-drawer__footer">
              <el-button style="width: 190px" @click="resultDialog = false">取 消</el-button>
              <el-button style="width: 190px" type="primary" @click="addResult">确 定</el-button>
            </div>
          </div>
        </el-drawer>
      </div>
      <div style="margin-top: 100px;margin-left: 300px" class="demo-drawer__footer">
        <el-button style="width: 190px" type="primary" @click="addResultDrawer">保 存</el-button>
        <el-button style="width: 190px" @click="befoResultClose">关闭</el-button>
      </div>
    </el-drawer>
    <el-tabs :tab-position="tabPosition" v-model="activeName">
      <el-tab-pane name="first">
        <el-form @submit.native.prevent :model="queryParams" ref="queryForm" size="small" :inline="true"
                 label-width="68px">
          <el-form-item prop="assessTemName">
            <el-input
              v-model="queryParams.assessTemName"
              placeholder="搜索方案名称"
              clearable
              @keyup.enter.native="handleQuery"
              style="width: 150px"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" type="warning" @click="resetQuery">重置</el-button>
          </el-form-item>
          <el-button style="float: right;margin-right: 30px" @click="firstClickTab" type="success">新增绩效方案
          </el-button>

        </el-form>
        <el-table :data="projectList" style="width: 100%">
          <el-table-column prop="assessTemName" align="center" label="模板名称"></el-table-column>
          <el-table-column prop="assessMode" align="center" label="考核方式"></el-table-column>
          <el-table-column prop="totalPoints" align="center" label="总分"></el-table-column>
          <el-table-column prop="createBy" align="center" label="创建人"></el-table-column>
          <el-table-column prop="updateTime" align="center" label="更新时间">
            <template slot-scope="scope">
              {{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="操作">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="editProject(scope.row.id)"
              >编辑
              </el-button>
              <el-button
                size="mini"
                type="text"
                @click="handleExport(scope.row.id)"
              >下载
              </el-button>
              <el-button
                size="mini"
                type="text"
                @click="getPreview(scope.row.id)">预览
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList()"
        />
        <el-drawer
          title="编辑考核方案信息"
          :before-close="handleClose"
          :visible.sync="editDialog"
          size="70%"
          direction="ltr"
          custom-class="demo-drawer"
          ref="drawer"
        >
          <div style="margin: 50px;padding-left: 380px" class="demo-drawer__content">
            <el-form :model="basicInfo">
              <el-form-item prop="assessTemName" label="考核名称">
                <el-input style="width: 300px" v-model="basicInfo.assessTemName"></el-input>
              </el-form-item>
              <el-form-item prop="assessMode" label="考核方式">
                <el-select v-model="basicInfo.assessMode" placeholder="请选择">
                  <el-option value="KPI考核"></el-option>
                  <el-option value="OKR考核"></el-option>
                </el-select>
              </el-form-item>

              <el-form-item label="考核周期" prop="assessPeriod">
                <el-select v-model="basicInfo.assessPeriod" placeholder="请选择">
                  <el-option value="月度"></el-option>
                  <el-option value="季度"></el-option>
                  <el-option value="年度"></el-option>
                  <el-option value="其他"></el-option>
                </el-select>
              </el-form-item>

              <el-form-item label="备注">
                <el-input
                  type="textarea"
                  style="width: 300px;"
                  :autosize="{ minRows: 2, maxRows: 4}"
                  placeholder="请输入内容"
                  v-model="basicInfo.projectRemark"/>
              </el-form-item>
            </el-form>
            <div style="text-align: center;margin-right: 250px;margin-top: 50px" class="demo-drawer__footer">
              <el-button @click="handleClose">取 消</el-button>
              <el-button type="primary" @click="submitBasicInfo">确认</el-button>
            </div>
          </div>
        </el-drawer>
        <el-drawer
          title="编辑指标项"
          :before-close="targetInfoClose"
          :visible.sync="targetDrawer"
          size="70%"
          direction="ltr"
          custom-class="demo-drawer"
          ref="drawer"
        >
          <div class="demo-drawer__content">
            <hr>
            <h2>当前维度权重合计: {{ mite.weight + '%' }} | 总分: {{ mite.sum + '分' }} |
              指标权重合计：{{ tarWeight + '%' }}
              <el-button style="float: right" type="primary" @click="targetDimensionalityFlag = true">添加指标维度
              </el-button>
            </h2>
            <div v-for="(item,inx) in tab" :key="inx">
              <el-card class="box-card">
                <div slot="header" class="clearfix">
                  <div style="float: left;margin-top: 5px;">
                    <span style="font-size: 20px">{{ item.dim.dimensionalityName }}&nbsp;&nbsp;&nbsp;</span>
                    <span style="font-size: 14px"><i>&nbsp;&nbsp;&nbsp;{{ item.dim.targetType }}</i></span>
                    <span style="font-size: 15px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;维度权重合计：&nbsp;&nbsp;{{
                        item.dim.weight + '%'
                      }}</span>
                    <span style="font-size: 15px">&nbsp;&nbsp;&nbsp;&nbsp;分数合计：{{ item.dim.sum }}</span>
                  </div>
                  <div style="float: right;">
                    <el-button style="font-size: 20px" type="text" @click="editTab(inx)"
                               icon="el-icon-edit"></el-button>
                    <el-button style="font-size: 20px" type="text" @click="delDimTab(item.dim)"
                               icon="el-icon-delete"></el-button>
                  </div>
                </div>
                <el-table :header-cell-style="{'text-align':'center'}" :data="item.data" style="width: 100%">
                  <el-table-column align="center" prop="targetLabel" label="指标名称"></el-table-column>
                  <el-table-column align="center" prop="targetInfo" label="指标说明"></el-table-column>
                  <el-table-column align="center" prop="assessCriterion" label="考核标准"></el-table-column>
                  <el-table-column align="center" prop="weight" label="指标权重">
                    <template slot-scope="scope">
                      {{ scope.row.weight }}
                      %
                    </template>
                  </el-table-column>
                  <el-table-column align="center" prop="scoreCeiling" label="评分分数">
                    <template slot-scope="scope">
                      {{ scope.row.scoreCeiling }}
                      分
                    </template>
                  </el-table-column>
                  <el-table-column lo label="操作" align="center">
                    <template slot-scope="scope">
                      <el-button type="text" @click="editLine(scope.$index,scope)">编辑</el-button>
                      <el-button type="text" @click="delTarget(inx,scope.$index,scope.row)">删除</el-button>
                    </template>
                  </el-table-column>
                </el-table>
                <el-button @click="addLine(inx)">新增指标</el-button>
                <el-button @click="selectLine(inx)">从指标库选择</el-button>
              </el-card>
            </div>
            <div style="text-align: center;margin-right: 250px;margin-top: 50px" class="demo-drawer__footer">
              <el-button @click="targetInfoClose()">取 消</el-button>
              <el-button type="primary" @click="submitTab">确认</el-button>
            </div>
          </div>
        </el-drawer>
        <el-dialog title="职能部门基础岗位绩效考核表" :before-close="closePreview" :visible.sync="previewIndex"
                   width="70%" center>
          <div>
            <el-table
              :data="targetResultVO"
              :span-method="objectSpanMethod"
              border
              style=" margin-top: 20px">
              <el-table-column align="center" prop="dimensionalityName" label="类别">
                <template slot-scope="scope">
                  <span v-if="scope.row.dimensionalityName != null">{{ scope.row.dimensionalityName }}</span>
                  <span v-if="scope.row.dimensionalityName == null">----</span>
                </template>
              </el-table-column>
              <el-table-column align="center" prop="targetLabel" label="指标名称">
                <template slot-scope="scope">
                  <span v-if="scope.row.targetLabel != null">{{ scope.row.targetLabel }}</span>
                  <span v-if="scope.row.targetLabel == null">----</span>
                </template>
              </el-table-column>
              <el-table-column align="center" prop="weight" label="权重">
                <template slot-scope="scope">
                  <span v-if="scope.row.weight != null">{{ scope.row.weight + '%' }}</span>
                  <span v-if="scope.row.weight == null">{{ 0 + '%' }}</span>
                </template>
              </el-table-column>
              <el-table-column align="center" prop="targetInfo" label="指标描述">
                <template slot-scope="scope">
                  <span v-if="scope.row.targetInfo != null">{{ scope.row.targetInfo }}</span>
                  <span v-if="scope.row.targetInfo == null">----</span>
                </template>
              </el-table-column>
              <el-table-column align="center" prop="assessCriterion" label="计算方式">
                <template slot-scope="scope">
                  <span v-if="scope.row.assessCriterion != null">{{ scope.row.assessCriterion }}</span>
                  <span v-if="scope.row.assessCriterion == null">----</span>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <span slot="footer" class="dialog-footer">
              <el-button @click="closePreview">关闭</el-button>
          </span>
        </el-dialog>
      </el-tab-pane>
      <el-tab-pane name="second">
        <el-button style="float: left" @click="secondTopClick">返回</el-button>
        <el-steps :active="1" :space="500" align-center>
          <el-step title="基础信息"></el-step>
          <el-step title="指标设置"></el-step>
          <el-step title="结果设置"></el-step>
        </el-steps>
        <br>
        <hr>
        <div style="margin: 50px;padding-left: 380px">
          <div>
            <el-form ref="basicInfoRef" :rules="basicInfoRules" label-position="right" label-width="80px"
                     :model="basicInfo">
              <el-row>
                <el-col :span="12">
                  <el-form-item prop="assessTemName" label="考核名称">
                    <el-input v-model="basicInfo.assessTemName"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item prop="assessMode" label="考核方式">
                    <el-select v-model="basicInfo.assessMode" placeholder="请选择">
                      <el-option value="KPI考核"></el-option>
                      <el-option value="OKR考核"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="考核周期" prop="assessPeriod">
                    <el-select v-model="basicInfo.assessPeriod" placeholder="请选择">
                      <el-option value="月度"></el-option>
                      <el-option value="季度"></el-option>
                      <el-option value="年度"></el-option>
                      <el-option value="其他"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="备注">
                    <el-input
                      type="textarea"
                      style="width: 300px;"
                      :autosize="{ minRows: 2, maxRows: 4}"
                      placeholder="请输入内容"
                      v-model="basicInfo.projectRemark"/>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </div>
          <div style="padding-left: 180px">
            <el-button @click="secondTopClick">取消</el-button>
            <el-button @click="secondNextClick" type="primary">下一步</el-button>
          </div>
        </div>
      </el-tab-pane>
      <el-tab-pane name="third">
        <el-button style="float: left" @click="secondTopClick">返回</el-button>
        <el-steps :active="2" :space="500" align-center>
          <el-step title="基础信息"></el-step>
          <el-step title="指标设置"></el-step>
          <el-step title="结果设置"></el-step>
        </el-steps>
        <br>
        <hr>
        <h2>当前维度权重合计: {{ mite.weight + '%' }} | 总分: {{ mite.sum + '分' }} | 指标权重合计：{{ tarWeight + '%' }}
          <el-button style="float: right" type="primary" @click="targetDimensionalityFlag = true">添加指标维度
          </el-button>
        </h2>

        <br>
        <div v-for="(item,inx) in tab" :key="inx">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <div style="float: left;margin-top: 5px;">
                <span style="font-size: 20px">{{ item.dim.dimensionalityName }}&nbsp;&nbsp;&nbsp;</span>
                <span style="font-size: 14px"><i>&nbsp;&nbsp;&nbsp;{{ item.dim.targetType }}</i></span>
                <span style="font-size: 15px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;维度权重合计：&nbsp;&nbsp;{{
                    item.dim.weight + '%'
                  }}</span>
                <span style="font-size: 15px">&nbsp;&nbsp;&nbsp;&nbsp;分数合计：{{ item.dim.sum }}</span>
              </div>
              <div style="float: right;">
                <el-button style="font-size: 20px" type="text" @click="editTab(inx)" icon="el-icon-edit"></el-button>
                <el-button style="font-size: 20px" type="text" @click="delTab(inx)" icon="el-icon-delete"></el-button>
              </div>
            </div>
            <el-table :header-cell-style="{'text-align':'center'}" :data="item.data" style="width: 100%">
              <el-table-column align="center" prop="targetLabel" label="指标名称"></el-table-column>
              <el-table-column align="center" prop="targetInfo" label="指标说明"></el-table-column>
              <el-table-column align="center" prop="assessCriterion" label="考核标准"></el-table-column>
              <el-table-column align="center" prop="weight" label="指标权重">
                <template slot-scope="scope">
                  {{ scope.row.weight }}
                  %
                </template>
              </el-table-column>
              <el-table-column align="center" prop="scoreCeiling" label="评分分数">
                <template slot-scope="scope">
                  {{ scope.row.scoreCeiling }}
                  分
                </template>
              </el-table-column>
              <el-table-column lo label="操作" align="center">
                <template slot-scope="scope">
                  <el-button type="text" @click="editLine(scope.$index,scope)">编辑</el-button>
                  <el-button type="text" @click="delLine(inx,scope.$index)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
            <el-button @click="addLine(inx)">新增指标</el-button>
            <el-button @click="selectLine(inx)">从指标库选择</el-button>
          </el-card>
        </div>

        <div style="margin: 50px;padding-left: 380px">
          <div style="padding-left: 180px">
            <el-button @click="thirdTopClick">上一步</el-button>
            <el-button @click="fourthClick" type="primary">下一步</el-button>
          </div>
        </div>
      </el-tab-pane>
      <el-tab-pane name="fourth">
        <el-button style="float: left" @click="secondTopClick">返回</el-button>
        <el-steps :active="3" :space="500" align-center>
          <el-step title="基础信息"></el-step>
          <el-step title="指标设置"></el-step>
          <el-step title="结果设置"></el-step>
        </el-steps>
        <br>
        <hr>
        <el-table
          :data="targetResultList">
          <el-table-column align="center" prop="grade" label="等级">
            <template slot-scope="scope">
              <el-input class="TargetInput" type="text" style="width: 80px" v-model="scope.row.grade"/>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="coefficient" label="系数">
            <template slot-scope="scope">
              <el-input-number class="TargetInput" :min="0.00" :max="100.00"
                               style="width: 80px"
                               :controls="false" v-model="scope.row.coefficient" :precision="2">
              </el-input-number>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="startScore" label="分数范围">
            <template slot-scope="scope">
              <el-input-number class="TargetInput" :min="1.00" :max="1000.00"
                               style="width: 80px"
                               :controls="false" v-model="scope.row.startScore" :precision="2">
              </el-input-number>
              ≤ 分数 ≤
              <el-input-number class="TargetInput" :min="1.00" :max="1000.00"
                               style="width: 80px"
                               :controls="false" v-model="scope.row.endScore" :precision="2">
              </el-input-number>
            </template>
          </el-table-column>
          <el-table-column align="center" label="操作">
            <template slot-scope="scope">
              <el-button @click="removeResult(scope.row)" class="el-icon-delete"></el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-button @click="resultflag = true" type="primary">新增</el-button>
        <el-drawer
          title="结果设置!"
          :append-to-body="true"
          :before-close="resultflagClose"
          :visible.sync="resultflag"
          direction="rtl">
          <div style="margin-left: 60px" class="demo-drawer__content">
            <el-form ref="form" :model="resultForm" label-width="80px">
              <el-row :gutter="20">
                <el-col :span="18">
                  <el-form-item label="等级">
                    <el-input v-model="resultForm.grade"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="10">
                  <el-form-item label="系数">
                    <el-input-number :min="0.00" :max="99.00"

                                     :controls="false" v-model="resultForm.coefficient" :precision="2">
                    </el-input-number>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="9">
                  <el-form-item label="分数范围">
                    <el-input-number :min="1.00" :max="100.00"
                                     style="width: 100px"
                                     :controls="false" v-model="resultForm.startScore" :precision="2">
                    </el-input-number>
                  </el-form-item>
                </el-col>
                <el-col :span="9">
                  <el-form-item label="≤ 分数 ≤">
                    <el-input-number :min="1.00" :max="100.00"
                                     style="width: 100px"
                                     :controls="false" v-model="resultForm.endScore" :precision="2">
                    </el-input-number>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
            <div style="margin-top: 50px" class="demo-drawer__footer">
              <el-button style="width: 190px" @click="resultflagClose">取 消</el-button>
              <el-button style="width: 190px" type="primary" @click="addRes">确 定</el-button>
            </div>
          </div>
        </el-drawer>
        <el-dialog title="职能部门基础岗位绩效考核表" :visible.sync="preview" width="70%" center>
          <div>
            <el-table
              :data="targetResultVO"
              :span-method="objectSpanMethod"
              border
              style=" margin-top: 20px">
              <el-table-column align="center" prop="dimensionalityName" label="类别">
                <template slot-scope="scope">
                  <span v-if="scope.row.dimensionalityName != null">{{ scope.row.dimensionalityName }}</span>
                  <span v-if="scope.row.dimensionalityName == null">----</span>
                </template>
              </el-table-column>
              <el-table-column align="center" prop="targetLabel" label="指标名称">
                <template slot-scope="scope">
                  <span v-if="scope.row.targetLabel != null">{{ scope.row.targetLabel }}</span>
                  <span v-if="scope.row.targetLabel == null">----</span>
                </template>
              </el-table-column>
              <el-table-column align="center" prop="weight" label="权重">
                <template slot-scope="scope">
                  <span v-if="scope.row.weight != null">{{ scope.row.weight + '%' }}</span>
                  <span v-if="scope.row.weight == null">{{ 0 + '%' }}</span>
                </template>
              </el-table-column>
              <el-table-column align="center" prop="targetInfo" label="指标描述">
                <template slot-scope="scope">
                  <span v-if="scope.row.targetInfo != null">{{ scope.row.targetInfo }}</span>
                  <span v-if="scope.row.targetInfo == null">----</span>
                </template>
              </el-table-column>
              <el-table-column align="center" prop="assessCriterion" label="计算方式">
                <template slot-scope="scope">
                  <span v-if="scope.row.assessCriterion != null">{{ scope.row.assessCriterion }}</span>
                  <span v-if="scope.row.assessCriterion == null">----</span>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <span slot="footer" class="dialog-footer">
              <el-button @click="preview = false">关闭</el-button>

          </span>
        </el-dialog>
        <div style="margin: 50px;padding-left: 380px">
          <div style="padding-left: 180px">
            <el-button @click="fourthTopClick">上一步</el-button>
            <el-button @click="fourthInfoClick">预览</el-button>
            <el-button @click="save" type="primary">保存</el-button>
          </div>
        </div>
      </el-tab-pane>
      <el-tab-pane name="sixth">
        <el-button style="float: left" @click="secondTopClick">返回</el-button>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import {
  selectList,
  addBasicInfo,
  selectTargetById,
  deleteDimeById,
  deleteTargetById,
  getResultByProId,
  addTargetResult,
  deleteProjectById,
  deleteDimeByProId,
  selectPreviewByProId,
  addProject,
  getTargetProjectById,
  updateTargetProject,
  selectTabResult,
  updateTab,
  selectResultByProId,
  editResult,
  deleteResult
} from "@/api/system/assessproject";
import {
  selectTreeList,
  addTarget,
  selectListByType,
  selectTargetTypeById,
  getTargetLabel
} from '@/api/system/targetlib'
import Template from "@/views/system/email/ItoTemplate";


export default {

  components: {Template},
  props: ["msg"],
  // name: "assessproject",
  data() {
    return {
      tarWeight: 0,
      resultflag: false,
      drawer: false,
      dimIndex: null,
      targetDrawer: false,
      editDialog: false,
      previewIndex: false,
      targetList: [],
      selectLineFlag: false,
      testArr1: [],
      testPosition1: 0,
      testPosition2: 0,
      tab: [
        {
          dim: {
            dimensionalityName: '业绩指标',
            targetType: '业绩指标',
            weight: 50.00,
            sum: 0,
            proId: 0
          },
          data: []
        }
      ],
      mite: {
        weight: 0,
        sum: 0,
      },
      dimeRules: {
        dimensionalityName: [
          {required: true, message: '维度名称不能为空', trigger: 'blur'}
        ],
        weight: [
          {required: true, message: '维度权重不能为空', trigger: 'blur'}
        ]
      },
      targetRules: {
        targetLabel: [
          {required: true, message: '指标名称不能为空', trigger: 'blur'},
        ],
        scoreCeiling: [
          {required: true, message: '指标分数上限不能为空', trigger: 'blur'}
        ],
        weight: [
          {required: true, message: '指标权重不能为空', trigger: 'blur'}
        ]
      },
      resultForm: {
        grade: '',
        coefficient: 0.00,
        startScore: 0.00,
        endScore: 0.00,
        proId: 0
      },
      resultDialog: false,
      targetResultVO: [],
      targetResultList: [
        {grade: 'S', coefficient: 1.00, startScore: 9.5, endScore: 10.0, proId: 0},
        {grade: 'A', coefficient: 0.90, startScore: 9.0, endScore: 9.5, proId: 0},
        {grade: 'B', coefficient: 0.80, startScore: 8.5, endScore: 9.0, proId: 0},
        {grade: 'C', coefficient: 0.70, startScore: 8.0, endScore: 8.5, proId: 0}
      ],
      data: [],
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      drawerTitle: '编辑指标维度',
      targetForm: {
        id: null,
        typeId: null,
        targetType: null,
        targetLabel: null,
        targetInfo: null,
        assessCriterion: null,
        scoreCeiling: null,
        weight: null,
        targetRemark: null,
        isDelete: null,
        status: '0'
      },
      targetType: {
        id: undefined,
        label: '',
        parentId: undefined
      },
      treeDataValue: '',
      treeData: '',
      scoreSum: 0,
      tabPosition: 'bottom',
      activeName: 'first',
      showSearch: true,
      projectList: [],
      targetDimensionalityList: [],
      basicInfo: {},
      targetDimensionality: {
        targetType: '业绩指标'
      },
      dimensionalityList: [],
      targetDimensionalityFlag: false,
      targetFlag: false,
      preview: false,
      queryParams: {
        id: null,
        pageNum: 1,
        pageSize: 10,
        assessTemName: ''
      },
      total: 0,
      basicInfoRules: {
        assessTemName: [
          {required: true, message: '请输入模板名称', trigger: 'blur'}
        ],
        assessMode: [
          {required: true, message: '请选择考核方式', trigger: 'change'}
        ]
      },
      index: 0,
      targetParams: {
        pageNum: 1,
        pageSize: 10,
        typeId: 1,
        targetLabel: ''
      },
      multipleSelection: [],
      targetIndex: 0,
      lintotal: 0
    }
  },
  created() {
    this.getList()
    this.getTree()
    this.changeMite()
  },
  methods: {
    resultflagClose() {
      this.resultflag = false
      this.resultForm = {}
    },
    closeDime() {
      this.changeMite();
      this.targetDimensionalityFlag = false
    },
    handleSelectionChange(selection) {
      this.multipleSelection = selection
    },
    selectionTarget() {
      this.multipleSelection.map(e => {
        this.tab[this.targetIndex].data.push(e)
      })
      let sum = 0;
      this.tab[this.targetIndex].data.map(e => sum += e.scoreCeiling)
      this.tab[this.targetIndex].dim.sum = sum
      this.selectLineFlag = false
      this.changeMite()
    },
    editTab(index) {
      this.targetDimensionalityFlag = true;
      this.targetDimensionality = this.tab[index].dim
      this.dimIndex = index
      this.changeMite()
    },
    editLine(index, scope) {
      this.targetForm = scope.row
      this.targetForm.index = index
      if (scope.row.id !== undefined && scope.row.id !== null) {
        selectTargetTypeById(this.targetForm.typeId).then(res => {
          this.treeData = res.msg
        })
      }
      this.targetFlag = true
    },
    delTarget(tabIdx, lineIdx, row) {
      if (row.id != null) {
        deleteTargetById(row.id, this.basicInfo.id).then(res => {
          this.tab[tabIdx].data.splice(lineIdx, 1);
          let sum = 0;
          this.tab[this.index].data.map(e => sum += e.scoreCeiling)
          this.tab[this.index].dim.sum = sum
          this.changeMite()
        })
      } else {
        this.tab[tabIdx].data.splice(lineIdx, 1);
        let sum = 0;
        this.tab[this.index].data.map(e => sum += e.scoreCeiling)
        this.tab[this.index].dim.sum = sum
        this.changeMite()
      }

    },
    delLine(tabIdx, lineIdx) {
      this.tab[tabIdx].data.splice(lineIdx, 1);
      let sum = 0;
      this.tab[this.index].data.map(e => sum += e.scoreCeiling)
      this.tab[this.index].dim.sum = sum
      this.changeMite()
    },
    addLine(index) {
      this.targetFlag = true;
      this.index = index
      this.treeDataValue = ''
      this.treeData = ''
    },
    selectLine(index) {
      this.selectLineFlag = true
      this.loading = true
      selectListByType(this.targetParams).then(res => {
        this.lintotal = res.total
        this.targetList = res.rows
        this.targetIndex = index
        this.loading = false
      })
    },
    changeMite() {
      let sum = 0;
      let weight = 0;
      let tarWeight = 0;
      this.tab.map(e => {
          sum += e.dim.sum;
        }
      )
      this.tab.map(e => {
        weight += e.dim.weight

      })
      this.tab.map(e => {
        e.data.map(w => {
          tarWeight += w.weight;
        })
      })
      this.tarWeight = tarWeight;
      this.mite.weight = weight
      this.mite.sum = sum

    },
    addTarget() {
      this.$refs["targetForm"].validate(valid => {
        if (valid) {
          if (this.targetForm.index != null) {
            this.targetForm.targetType = this.tab[this.index].dim.targetType
            this.tab[this.index].data[this.targetForm.index] = this.targetForm
            let sum = 0;
            this.tab[this.index].data.map(e => {
              sum += e.scoreCeiling;
            })
            this.tab[this.index].dim.sum = sum
            this.changeMite()
          } else {
            this.targetForm.targetType = this.tab[this.index].dim.targetType
            this.tab[this.index].data.push(this.targetForm);
            let sum = 0;
            this.tab[this.index].data.map(e => sum += e.scoreCeiling)
            this.tab[this.index].dim.sum = sum
            this.changeMite()
          }
          this.reTargetCel()
        }
      })
    },
    delTab(index) {
      // let len = this.tab.length - 1;
      this.tab.splice(index, 1);
      this.changeMite()
    },
    delDimTab(dim) {
      if (dim.id != null && dim.id != undefined) {
        deleteDimeById(dim.id, dim.proId).then(res => {
          let len = this.tab.length - 1;
          this.tab.splice(len, 1);
          this.changeMite()
        })
      } else {
        let len = this.tab.length - 1;
        this.tab.splice(len, 1);
        this.changeMite()
      }
    },
    convert(list) {
      const res = []
      const map = list.reduce((res, v) => (res[v.id] = v, v.children = [], res), {})
      for (const item of list) {
        if (item.parentId === 0) {
          res.push(item)
          continue
        }
        if (item.parentId in map) {
          const parent = map[item.parentId]
          parent.children = parent.children || []
          parent.children.push(item)
        }
      }
      return res;
    },
    getTree() {
      selectTreeList().then(resp => {
        let res = this.convert(resp.data);
        this.data = res
      })
    },
    getList() {
      selectList(this.queryParams).then(res => {
        this.projectList = res.rows
        // this.projectList.map(e => obj.push(e.itoAssessProject));
        // this.projectList = obj;
        this.total = res.total
      })
    },
    handleQuery() {
      this.getList();
    },
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        assessName: ''
      }
    },
    firstClickTab() {
      this.activeName = 'second'
    },
    secondTopClick() {
      this.activeName = 'first'
      this.cancel()
      this.resetCancel()
    },
    cancel() {
      if (this.basicInfo.id != undefined) {
        deleteProjectById(this.basicInfo.id).then(res => {
        })
      }
    },
    reTargetCel() {
      this.targetForm = {
        id: null,
        typeId: null,
        targetType: null,
        targetLabel: null,
        targetInfo: null,
        assessCriterion: null,
        scoreCeiling: null,
        weight: null,
        targetRemark: null,
        isDelete: null,
        status: '0'
      }
      this.targetFlag = false
    },
    resetCancel() {
      this.basicInfo = {}
      this.resultForm = {}
      this.targetForm = {
        id: null,
        typeId: null,
        targetType: null,
        targetLabel: null,
        targetInfo: null,
        assessCriterion: null,
        scoreCeiling: null,
        weight: null,
        targetRemark: null,
        status: '0',
        isDelete: null
      }
      this.treeData = ''
      this.treeDataValue = ''
      this.targetDimensionality = {
        targetType: '业绩指标'
      }
      this.tab.length = 0
      this.tab.push({
        dim: {
          dimensionalityName: '业绩指标',
          targetType: '业绩指标',
          weight: 50.00,
          sum: 0,
          proId: 0
        },
        data: []
      })
      this.mite = {
        weight: 0,
        sum: 0,
      }
      this.changeMite()
    },
    secondNextClick() {
      this.$refs["basicInfoRef"].validate(valid => {
        if (valid) {
          addBasicInfo(this.basicInfo).then(item => {
            this.basicInfo.id = item.data
            this.activeName = 'third'
            this.tab[0].dim.proId = this.basicInfo.id
          })
        }
      })
    },
    thirdTopClick() {
      this.activeName = 'second'
      this.cancel()

    },
    fourthTopClick() {
      this.activeName = 'third'
      if (this.basicInfo.id != undefined) {
        deleteDimeByProId(this.basicInfo.id).then(res => {
        })
      }

      this.getDimensionality()
    },
    fourthClick() {
      this.$confirm('是否保存指标设置并进入结果设置?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (this.mite.weight == 100) {
          if (this.mite.sum > 0) {
            if (this.tarWeight == 100) {
              let data = [];
              try {
                this.tab.map(e => {
                  if (e.data.length <= 0) {
                    data = [];
                    throw new Error();
                  } else {
                    data = e.data
                  }
                })
              } catch (e) {
              }
              if (data.length <= 0) {
                this.$message({
                  type: 'error',
                  message: '同一维度下指标不能为空！'
                });
              } else {
                this.activeName = 'fourth'
              }
            } else if (this.tarWeight < 100) {
              this.$message({
                type: 'error',
                message: '当前所有指标权重合计小于100%!'
              });
            } else if (this.tarWeight > 100) {
              this.$message({
                type: 'error',
                message: '当前所有指标权重合计大于100%!'
              });
            }
          } else {
            this.$message({
              type: 'error',
              message: '当前维度总分不能小于‘1分’'
            });
          }

        } else if (this.mite.weight < 100) {
          this.$message({
            type: 'error',
            message: '当前权重合计小于100%!'
          });
        } else if (this.mite.weight > 100) {
          this.$message({
            type: 'error',
            message: '当前权重合计大于100%!'
          });
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消保存'
        });
      });
    },
    fourthInfoClick() {
      this.preview = true
      this.getDimensionality()
    },
    getDimensionality() {
      this.testArr1 = []
      this.testPosition1 = 0
      let array = []
      for (let i = 0; i < this.tab.length; i++) {
        for (let j = 0; j < this.tab[i].data.length; j++) {
          this.tab[i].data[j].dimensionalityName = this.tab[i].dim.dimensionalityName
          array.push(this.tab[i].data[j])
        }
      }
      this.targetResultVO = array
      this.rowspan(this.testArr1, this.testPosition1, "dimensionalityName");
    },
    dimensionalitySubmit() {
      this.$refs["dimeForm"].validate(valid => {
        if (valid) {
          this.targetDimensionality.proId = this.basicInfo.id
          this.targetDimensionality.sum = 0
          if (this.targetDimensionality != null && this.dimIndex != null) {
            this.tab[this.dimIndex].dim = this.targetDimensionality;
            let sum = 0;
            this.tab[this.index].data.map(e => sum += e.scoreCeiling)
            this.tab[this.dimIndex].dim.sum = sum
            this.changeMite()
            this.dimIndex = null
          } else {
            const newTab = {
              dim: this.targetDimensionality,
              data: []
            }
            this.tab.push(newTab);
            this.changeMite()

          }
          this.targetDimensionality = {
            targetType: '业绩指标'
          }
          this.targetDimensionalityFlag = false
        }
      })

    },
    resetForm() {
      this.targetForm =
        {
          id: null,
          typeId: null,
          targetType: null,
          targetLabel: null,
          targetInfo: null,
          assessCriterion: null,
          scoreCeiling: null,
          weight: null,
          targetRemark: null,
          status: '0',
          isDelete: null
        }
      this.treeData = ''
      this.treeDataValue = ''
      this.editTargetFlag = false
    },
    handNodeClick(data, node, nodeData) {
      this.treeDataValue = data
      this.treeData = data.label
      this.targetForm.typeId = data.id
    },
    selectTargetBy(dimId) {
      selectTargetById(dimId).then(res => {
        this.targetDimensionalityList = res.data
      })
    },
    rowspan(spanArr, position, spanName) {
      this.targetResultVO.forEach((item, index) => {
        if (index === 0) {
          spanArr.push(1);
          position = 0;
        } else {
          if (
            this.targetResultVO[index][spanName] ===
            this.targetResultVO[index - 1][spanName]
          ) {
            spanArr[position] += 1;
            spanArr.push(0);
          } else {
            spanArr.push(1);
            position = index;
          }
        }
      });
    },
    objectSpanMethod({row, column, rowIndex, columnIndex}) {
      if (columnIndex === 0) {
        const _row = this.testArr1[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col,
        };
      }
    },
    addRes() {
      this.resultForm.proId = this.basicInfo.id
      this.targetResultList.push(this.resultForm)
      this.resultForm = {}
      this.resultflag = false
    },
    addResult() {
      this.resultForm.proId = this.basicInfo.id
      this.targetResultList.push(this.resultForm)
      this.resultForm = {}
      this.resultDialog = false
    },
    removeResult(row) {
      if (row.id != null) {
        deleteResult(row.id).then(res => {
          var index = this.targetResultList.indexOf(row)
          if (index !== -1) {
            this.targetResultList.splice(index, 1)
          }
        })
      } else {
        var index = this.targetResultList.indexOf(row)
        if (index !== -1) {
          this.targetResultList.splice(index, 1)
        }
      }

    },
    save() {
      this.$confirm('是否保存结果设置?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (this.targetResultList.length > 0) {
          this.targetResultList.map(e => e.proId = this.basicInfo.id)
          addTargetResult(this.targetResultList).then(res => {
            addProject(this.tab, this.mite.sum).then(res => {
              this.resetCancel()
              this.getList()
              this.$message({
                type: 'success',
                message: '已保存!'
              });
              this.activeName = 'first'
            })
          })
        } else {
          this.$message({
            type: 'error',
            message: '至少添加一条绩效结果'
          });
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消保存'
        });
      });
    },
    /** 导出按钮操作 */
    handleExport(id) {
      this.queryParams.id = id
      this.download('system/assessproject/export', {
        ...this.queryParams
      }, `考核方案_${new Date().getTime()}.xlsx`)
      this.queryParams.id = null
    },
    handleNodeClick(data) {
      this.targetParams.typeId = data.id
      this.loading = true
      this.selectLine(this.targetIndex);
    },
    getPreview(id) {
      this.previewIndex = true
      selectPreviewByProId(id).then(res => {
        this.testArr1 = []
        this.testPosition1 = 0
        this.targetResultVO = res.data
        this.rowspan(this.testArr1, this.testPosition1, "dimensionalityName");
      })
    },
    closePreview() {
      this.testArr1 = []
      this.testPosition1 = 0
      this.targetResultVO = []
      this.previewIndex = false
    },
    editProject(id) {
      getTargetProjectById(id).then(res => {
        this.basicInfo = res.data
        this.editDialog = true
      })
    },
    handleClose() {
      this.editDialog = false
      this.basicInfo = {}
    },
    submitBasicInfo() {
      this.$confirm('是否保存基础信息并进入指标设置?', '提示', {
        distinguishCancelAndClose: true,
        confirmButtonText: '设置指标',
        cancelButtonText: '不设置指标',
        type: 'warning'
      }).then(() => {
        updateTargetProject(this.basicInfo).then(res => {
          this.$message({
            type: 'success',
            message: '已保存基础信息'
          });
          selectTabResult(this.basicInfo.id).then(res => {
            this.tab = res.data
            this.changeMite()
            this.targetDrawer = true
            selectResultByProId(this.basicInfo.id).then(res => {
              this.targetResultList = res.data
            })
            this.editDialog = false
            this.getList()
          })
        })
      }).catch((action) => {
        updateTargetProject(this.basicInfo).then(res => {
          if (action === 'cancel') {
            this.$message({
              type: 'success',
              message: '已保存基础信息'
            })
            this.getList()
            this.handleClose()
          } else if (action === 'close') {
            this.$message({
              type: 'info',
              message: '已取消保存'
            })
          }
        })
      });
    },
    targetInfoClose() {
      this.basicInfo = {}
      this.targetClose()
    },
    targetClose() {
      this.getList()
      this.targetResultList = [
        {grade: 'S', coefficient: 1.00, startScore: 9.5, endScore: 10.0, proId: 0},
        {grade: 'A', coefficient: 0.90, startScore: 9.0, endScore: 9.5, proId: 0},
        {grade: 'B', coefficient: 0.80, startScore: 8.5, endScore: 9.0, proId: 0},
        {grade: 'C', coefficient: 0.70, startScore: 8.0, endScore: 8.5, proId: 0}
      ]
      this.targetDrawer = false
      this.tab.length = 0
      this.tab.push({
        dim: {
          dimensionalityName: '业绩指标',
          targetType: '业绩指标',
          weight: 50.00,
          sum: 0,
          proId: 0
        },
        data: []
      })
      this.mite = {
        sum: 0,
        weight: 0
      };
      this.tarWeight = 0
    },
    befoResultClose() {
      this.targetClose()
      this.drawer = false
      this.basicInfo = {}
      this.resultForm = {}

    },
    resultClose() {
      this.resultDialog = false
      this.resultForm = {}
    },
    closeTarget() {
      this.selectLineFlag = false
    },
    submitTab() {
      this.$confirm('是否保存指标并修改系数级别', '提示', {
        distinguishCancelAndClose: true,
        confirmButtonText: '修改系数级别',
        cancelButtonText: '不修改系数级别',
        type: 'warning'
      }).then(() => {
        if (this.mite.weight == 100) {
          if (this.mite.sum > 0) {
            if (this.tarWeight == 100) {
              let data = [];
              try {
                this.tab.map(e => {
                  if (e.data.length <= 0) {
                    data = [];
                    throw new Error();
                  } else {
                    data = e.data
                  }
                })
              } catch (e) {
              }
              if (data.length <= 0) {
                this.$message({
                  type: 'error',
                  message: '同一维度下指标不能为空！'
                });
              } else {
                updateTab(this.tab, this.mite.sum).then(res => {
                  selectTabResult(this.basicInfo.id).then(res => {
                    this.tab = res.data
                    this.drawer = true;
                    selectResultByProId(this.basicInfo.id).then(res => {
                      this.targetResultList = res.data
                    })
                    this.targetClose()
                  })
                  this.$message({
                    type: 'success',
                    message: '已保存指标信息'
                  });
                })
              }
            } else if (this.tarWeight < 100) {
              this.$message({
                type: 'error',
                message: '当前所有指标权重合计小于100%!'
              });
            } else if (this.tarWeight > 100) {
              this.$message({
                type: 'error',
                message: '当前所有指标权重合计大于100%!'
              });
            }
          } else {
            this.$message({
              type: 'error',
              message: '当前维度总分不能小于‘1分’'
            });
          }

        } else if (this.mite.weight < 100) {
          this.$message({
            type: 'error',
            message: '当前权重合计小于100%!'
          });
        } else if (this.mite.weight > 100) {
          this.$message({
            type: 'error',
            message: '当前权重合计大于100%!'
          });
        }
      }).catch((action) => {
        if (action === 'cancel') {
          if (this.mite.weight == 100) {
            if (this.mite.sum > 0) {
              if (this.tarWeight == 100) {
                let data = [];
                try {
                  this.tab.map(e => {
                    if (e.data.length <= 0) {
                      data = [];
                      throw new Error();
                    } else {
                      data = e.data
                    }
                  })
                } catch (e) {
                }
                if (data.length <= 0) {
                  this.$message({
                    type: 'error',
                    message: '同一维度下指标不能为空！'
                  });
                } else {
                  updateTab(this.tab, this.mite.sum).then(res => {
                    selectTabResult(this.basicInfo.id).then(res => {
                      this.tab = res.data
                    })
                    this.targetClose()
                    this.$message({
                      type: 'success',
                      message: '已保存指标信息'
                    });
                  })
                }
              } else if (this.tarWeight < 100) {
                this.$message({
                  type: 'error',
                  message: '当前所有指标权重合计小于100%!'
                });
              } else if (this.tarWeight > 100) {
                this.$message({
                  type: 'error',
                  message: '当前所有指标权重合计大于100%!'
                });
              }
            } else {
              this.$message({
                type: 'error',
                message: '当前维度总分不能小于‘1分’'
              });
            }

          } else if (this.mite.weight < 100) {
            this.$message({
              type: 'error',
              message: '当前权重合计小于100%!'
            });
          } else if (this.mite.weight > 100) {
            this.$message({
              type: 'error',
              message: '当前权重合计大于100%!'
            });
          }
        } else if (action === 'close') {
          this.$message({
            type: 'info',
            message: '已取消保存'
          })
        }
      })
    },
    addResultDrawer() {
      this.$confirm('是否保存结果设置', '提示', {
        confirmButtonText: '保存',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (this.targetResultList.length <= 0) {
          this.$message({
            type: 'error',
            message: '请添加考核结果'
          });
        } else {
          editResult(this.targetResultList).then(res => {
            this.befoResultClose()
            this.$message({
              type: 'success',
              message: '已保存结果设置'
            });
          })
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消保存结果设置'
        });
      })


    }
  }
}
</script>

<style scoped>
/*去掉切换时el-tab-pane底部的蓝色下划线*/
/deep/ .el-tabs__active-bar {
  background-color: transparent !important;
}

/*去掉tabs底部的下划线*/
/deep/ .el-tabs__nav-wrap::after {
  position: static !important;
}

.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both
}

/* 利用穿透，设置input边框隐藏 */
.TargetInput >>> .el-input__inner {
  border: 0;
}

/* 如果你的 el-input type 设置成textarea ，就要用这个了 */
.TargetInput >>> .el-textarea__inner {
  border: 0;
  resize: none; /* 这个是去掉 textarea 下面拉伸的那个标志，如下图 */
}

.targetdra {
  padding: 10px;
}
</style>
